﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Retirement_Admin_claim : System.Web.UI.Page
{
    Claim claim = new Claim();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //this.btn_confirm.Enabled = false;
            this.lb_invalidClaimMessage.Text = "";
            this.lb_msg.Text = "";
            this.lb_cbMsg.Text = "";
        }
        
    }
    protected void btn_confirm_Click(object sender, ImageClickEventArgs e)
    {
        this.lb_cbMsg.Text = "";
        this.lb_msg.Text = "";


        if (!this.cb_allFormsSubmitted.Checked)
        {
            this.lb_cbMsg.Text = "Please make sure that all necessary documents are received from the claimant!";
            return;
        }

        string policyNo = tb_searchPolicy.Text;
        
        claim.claimantName = this.tb_claimantName.Text;
        claim.claimantNric = this.tb_claimantNric.Text;
        claim.claimantDob = DateTime.ParseExact(this.tb_claimantDob.Text,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture);
        claim.claimantRelationshipToPolicyOwner = this.tb_relationship.Text;
        claim.claimDescription = this.tb_claimDescription.Text;

        try
        {
            claim.claim(policyNo, this.ddl_claimType.SelectedValue, Convert.ToDecimal(this.tb_claimAmount.Text));
            this.Response.Redirect("./caseSuccessful.aspx");
        }
        catch (RetirementException ex)
        {
            this.lb_msg.Text = ex.message;
            this.lb_msg.Visible = true;
        }   

    }


    protected void tbn_searchPolicy_Click(object sender, ImageClickEventArgs e)
    {
        Policy policy = Policy.getPolicy(this.tb_searchPolicy.Text);
        Customer customer = Customer.getCustomerInfo(policy.userId);
        
        this.lb_ownerName.Text = customer.firstName + " " + customer.lastName;
        int age = -1;
        age = Util.getAge(customer.dob);

        //this.lb_issueDate.Text = String.Format("{0:dd/MM/yyyy}", policy.issueDate);
        this.lb_issueDate.Text = policy.issueDate.ToString("MM/dd/yyyy");
        this.lb_policyNo.Text = policy.policyNo;
        this.lb_benefitType.Text = policy.benefitType;
        this.lb_basicSumInsured.Text = "S$" + policy.basicSumInsured.ToString("###,###.00");
        //this.lb_basicSumInsured.Text = String.Format("{0:C}",policy.basicSumInsured);

        if (policy.plusRiderSumInsured != null && policy.plusRiderSumInsured != 0)
        {
            this.lb_plusRider.Text = "Critical Care Plus Rider";
            this.lb_pluseRiderTerm.Text = Convert.ToString(65 - age) + " Years";
            this.lb_riderSumInsured.Text = "S$" + policy.plusRiderSumInsured.ToString("###,###.00");
           //this.lb_riderSumInsured.Text = String.Format("{0:C}", policy.plusRiderSumInsured);
        }

        if (policy.waiverRiderPremium != null && policy.plusRiderSumInsured != 0)
        {
            this.lb_waiverRider.Text = "Critical Care Waiver Rider";
            this.lb_waiverRiderTerm.Text = Convert.ToString(65 - age) + " Years";
        }

        this.lb_accountValue.Text = "S$" + policy.checkAccountValue(DateTime.Now).ToString("###,###.00");

    }

    protected void cb_allFormsSubmitted_CheckedChanged(object sender, EventArgs e)
    {
        if (this.cb_allFormsSubmitted.Checked)
        {

            this.btn_confirm.Enabled = true;
        }
        else
        {
            this.btn_confirm.Enabled = false;

        }
    }

    protected void btn_calculate_Click(object sender, ImageClickEventArgs e)
    {
        this.lb_invalidClaimMessage.Text = "";
        string policyNo = tb_searchPolicy.Text;   
        try
        {
            this.tb_claimAmount.Text = claim.getMaxClaimAmount(policyNo, this.ddl_claimType.SelectedValue).ToString("###,###.00");

        }
        catch (RetirementException error)
        {
            this.lb_invalidClaimMessage.Text = error.message;
            this.lb_invalidClaimMessage.Visible = true;
        }   
    }
    protected void btn_fillUpInfo_Click(object sender, EventArgs e)
    {
        this.tb_claimantName.Text = "Skye Tan";
        this.tb_relationship.Text = "Owner";
        this.tb_claimantNric.Text = "S9316175J";
        this.tb_claimantDob.Text = "08/05/1993";
        this.tb_claimDescription.Text = "Angioplasty Surgery";
    }
}